import {
  listInteractive,
  option
} from '../../api/blog'


// pages/collect/index.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    slideButtons: [{
      text: '删除',
      type: 'warn'
    }],
    list: []
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    // 点赞类型
    const type = 2
    listInteractive(type).then(res => {
      this.setData({
        list: res
      })
    })
  },

  cancelCollect(e) {
    const params = {
      blogId: e.currentTarget.dataset.id,
      type: 2,
      option: false
    }
    option(params).then(() => {
      const newList = []
      this.data.list.forEach(element => {
        if (element.id !== params.blogId) {
          newList.push(element)
        }
      })
      this.setData({
        list: newList
      })
    })
  },
  toDetail(e) {
    const id = e.currentTarget.dataset.id
    wx.navigateTo({
      url: `/pages/detail/index?id=${id}`,
    })
  }

})